package com.jiaotong.smart.smartjiaotong.controller;

import javax.annotation.Resource;

import com.jiaotong.smart.smartjiaotong.service.IntersectionService;
import com.jiaotong.smart.smartjiaotong.structure.CodeMsg;
import com.jiaotong.smart.smartjiaotong.structure.Result;
import com.jiaotong.smart.smartjiaotong.structure.IntersectionStruct.*;

import org.apache.ibatis.jdbc.Null;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 陈侗 信号监控接口
 */
@RestController
@RequestMapping("/intersections")
public class IntersectionController {

    @Resource
    IntersectionService intersectionService;

    @PostMapping("/getBaseInformation")
    // 获取道路基本信息
    public Result<IntersectionBaseInformationRes> getBaseInformation(@RequestBody IntersectionBaseInformationReq req) {
        return Result.success(intersectionService.getIntersectionBaseInformation(req));
    }

    @PostMapping("/setPhasedLocked")
    // 设置锁相
    public Result<Null> setPhasedLocked(@RequestBody IntersectionPhaseLockedReq req) {
        intersectionService.setIntersectionPhasedLocked(req);
        return Result.success(null);
    }

    @PostMapping("/setFlowDirection")
    // 设置流向
    public Result<Null> setFlowDirection(@RequestBody IntersectionFlowDirectionReq req) {
        intersectionService.setIntersectionFlowDirection(req);
        return Result.success(null);
    }

    @PostMapping("/setTimeSeriod")
    // 设置时间段
    public Result<Null> setTimeSeriod(@RequestBody SetIntersectionTimeSeriodReq req) {
        boolean res = intersectionService.setIntersectionTimeSeriod(req);
        return res ? Result.success(null) : Result.fail(CodeMsg.SERVER_ERROR);
    }

    @PostMapping("/getTimeSeriods")
    // 查看时间段方案
    public Result<GetIntersectionTimeSeriodRes> getTimeSeriods(@RequestBody GetIntersectionTimeSeriodReq req) {
        GetIntersectionTimeSeriodRes res = intersectionService.getIntersectionTimeSeriods(req);
        return Result.success(res);
    }

}
